<!DOCTYPE html>
<html lang="en" class="bg-white" xmlns:th="http://www.thymeleaf.org">
<head>
    <title>合同管理</title>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{../assets/libs/layui/css/layui.css}"/>
    <link rel="stylesheet" th:href="@{../assets/module/admin.css?v=311}"/>
</head>
<body>

<!-- 页面加载loading -->
<div class="page-loading">
    <div class="ball-loader">
        <span></span><span></span><span></span><span></span>
    </div>
</div>

<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-form toolbar layui-form-pane">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <select id="sltKey">
                            <option value="">请选择搜索条件</option>
                            <option value="sys_cs_name">联系人</option>
                            <option value="sys_cs_phone">联系电话</option>
                            <option value="sys_cs_id">合同编号</option>
                            <option value="sys_cs_company">公司名称</option>
                        </select>
                    </div>
                    <div class="layui-inline">
                        <input id="edtSearch" class="layui-input" type="text" placeholder="输入关键字"/>
                    </div>
                    <div class="layui-inline">
                        <button id="btnSearch" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索</button>
                        <button id="btnAdd" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>
                    </div>
                </div>
            </div>

            <table class="layui-table" id="userTable" lay-filter="userTable"></table>
        </div>
    </div>
</div>
<!-- js部分 -->
<script type="text/javascript" src="../assets/libs/layui/layui.js"></script>
<script type="text/javascript" src="../assets/js/common.js?v=311"></script>
<script>
    layui.use(['layer', 'form', 'table', 'util', 'laydate'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var util = layui.util;
        var laydate = layui.laydate;
        var str=localStorage.getItem("projects");
        var arr=[
            {type: 'checkbox'},
            {field: 'sys_cs_id',align: 'center', title: '合同编号'},
            {field: 'sys_cs_name', align: 'center',title: '联系人'},
            {field: 'sys_cs_phone',align: 'center', title: '联系方式'},
            {align: 'center', title: '代理项目',
                templet:function (item) {
                    return '<button class="layui-btn layui-btn-xs layui-btn-primary">'+getProjectName(item.sys_cs_project)+'</button>'
                }
            },
            {field: 'sys_cs_region',align: 'center', title: '所属区域'},
            {field: 'sys_company_address',align: 'center', title: '公司地址'},
            {field: 'sys_create_time',align: 'center', title: '加盟时间'},
            {align: 'center', title: '合同状态',
                templet:function (item) {
                    if (item.sys_cs_status==0) {
                        return "<button class='layui-btn layui-btn-xs layui-btn-disabled'>审核中</button>";
                    }
                    if (item.sys_cs_status==1) {
                        return "<button class='layui-btn layui-btn-xs layui-btn-primary'>已审核</button>";
                    }
                    if (item.sys_cs_status==2) {
                        return "<button class='layui-btn layui-btn-xs layui-btn-danger'>已到期</button>";
                    }
                }
            }
        ];
        function getProjectName(index) {
            var arr=str.split(",");
            return arr[index];
        }
        // 渲染表格
        laydate.render({
            elem: '#dateEnd'
            ,calendar: true
            ,done: function(value, date, endDate){
                var dateVule=new Date(value);
                console.log("起始前:"+value); //得到日期生成的值，如：2017-08-18
                if (startDate!=""){
                    if (parseInt(startDate)>parseInt(dateVule.getTime())) {
                        layer.msg("结束时间不得低于起始时间",{icon:5});
                        form.render('.date-icon', 'test1');
                    }
                } else {
                    layer.msg("请先选择起始时间",{icon:5});
                    form.render('select', 'test1');
                }
                startDate="";
            }
        });
        $('#btnSearch').click(function () {
            var key = $('#sltKey').val();
            var value = $('#edtSearch').val();
            if (value=="" || key=="") {
                layer.msg('请选择搜索条件', {icon: 2});
            }else {
                var insTb = table.render({
                    elem: '#userTable',
                    url: '/sys/franchisee/getFranchiseeByIf',
                    cellMinWidth: 100,
                    text: {
                        none: '暂无相关数据'
                    },
                    where: {searchKey: key, searchValue: value},
                    cols: [arr],
                    page:true
                    ,response: {
                        statusCode: 0 //重新规定成功的状态码为 200，table 组件默认为 0
                    }
                    ,parseData: function(res){ //将原始数据解析成 table 组件所规定的数据
                        if (res.total>0){
                            return {
                                "code": 0, //解析接口状态
                                "msg": res.message, //解析提示文本
                                "count": res.total, //解析数据长度
                                "data": res.list //解析数据列表
                            };
                        }
                    }
                });
            }
        });
        // 导出excel
        $('#btnExp').click(function () {
            var checkRows = table.checkStatus('logTable');
            if (checkRows.data.length == 0) {
                layer.msg('请选择要导出的数据', {icon: 2});
            } else {
                table.exportFile(insTb.config.id, checkRows.data, 'xls');
            }
        });
    });
</script>

</body>
</html>